/*   1:    */ package org.intellij.plugins.relaxNG.config;
/*   2:    */ 
/*   3:    */

import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.editor.HectorComponentPanel;
import com.intellij.openapi.editor.HectorComponentPanelsProvider;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.pointers.VirtualFilePointer;
import com.intellij.openapi.vfs.pointers.VirtualFilePointerManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.xml.XmlFile;
import com.intellij.psi.xml.XmlTag;
import com.intellij.util.xmlb.annotations.MapAnnotation;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.HashMap;
import java.util.Map;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */
/*  20:    */
/*  21:    */ 
/*  22:    */ @State(name="NoNamespaceConfig.Mappings", storages={@com.intellij.openapi.components.Storage(file="$WORKSPACE_FILE$")})
/*  23:    */ class NoNamespaceConfigImpl
/*  24:    */   extends NoNamespaceConfig
/*  25:    */   implements PersistentStateComponent<Mappings>
/*  26:    */ {
/*  27: 50 */   private final Map<VirtualFilePointer, VirtualFilePointer> a = new HashMap();
/*  28:    */   private final Project b;
/*  29:    */   
/*  30:    */   NoNamespaceConfigImpl(Project paramProject)
/*  31:    */   {
/*  32: 54 */     this.b = paramProject;
/*  33:    */   }
/*  34:    */   
/*  35:    */   private VirtualFilePointer a(@NotNull PsiFile paramPsiFile)
/*  36:    */   {
/*  37: 58 */     if (paramPsiFile == null) {
/*  38: 58 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/intellij/plugins/relaxNG/config/NoNamespaceConfigImpl", "getMappedPointer" }));
/*  39:    */     }
/*  40: 58 */     VirtualFile localVirtualFile = paramPsiFile.getVirtualFile();
/*  41: 59 */     if (localVirtualFile == null) {
/*  42: 59 */       return null;
/*  43:    */     }
/*  44: 61 */     String str = localVirtualFile.getUrl();
/*  45: 62 */     for (VirtualFilePointer localVirtualFilePointer : this.a.keySet()) {
/*  46: 63 */       if (str.equals(localVirtualFilePointer.getUrl())) {
/*  47: 64 */         return (VirtualFilePointer)this.a.get(localVirtualFilePointer);
/*  48:    */       }
/*  49:    */     }
/*  50: 67 */     return null;
/*  51:    */   }
/*  52:    */   
/*  53:    */   @Nullable
/*  54:    */   public String getMapping(@NotNull PsiFile paramPsiFile)
/*  55:    */   {
/*  56: 72 */     if (paramPsiFile == null) {
/*  57: 72 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/intellij/plugins/relaxNG/config/NoNamespaceConfigImpl", "getMapping" }));
/*  58:    */     }
/*  59: 72 */     VirtualFilePointer localVirtualFilePointer = a(paramPsiFile);
/*  60: 73 */     return localVirtualFilePointer != null ? localVirtualFilePointer.getUrl() : null;
/*  61:    */   }
/*  62:    */   
/*  63:    */   public VirtualFile getMappedFile(@NotNull PsiFile paramPsiFile)
/*  64:    */   {
/*  65: 77 */     if (paramPsiFile == null) {
/*  66: 77 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/intellij/plugins/relaxNG/config/NoNamespaceConfigImpl", "getMappedFile" }));
/*  67:    */     }
/*  68: 77 */     VirtualFilePointer localVirtualFilePointer = a(paramPsiFile);
/*  69: 78 */     return localVirtualFilePointer != null ? localVirtualFilePointer.getFile() : null;
/*  70:    */   }
/*  71:    */   
/*  72:    */   public void setMapping(@NotNull PsiFile paramPsiFile, String paramString)
/*  73:    */   {
/*  74: 82 */     if (paramPsiFile == null) {
/*  75: 82 */       throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/intellij/plugins/relaxNG/config/NoNamespaceConfigImpl", "setMapping" }));
/*  76:    */     }
/*  77: 82 */     VirtualFile localVirtualFile = paramPsiFile.getVirtualFile();
/*  78: 83 */     assert (localVirtualFile != null);
/*  79:    */     
/*  80: 85 */     String str = localVirtualFile.getUrl();
/*  81: 86 */     VirtualFilePointerManager localVirtualFilePointerManager = VirtualFilePointerManager.getInstance();
/*  82: 87 */     for (VirtualFilePointer localVirtualFilePointer : this.a.keySet()) {
/*  83: 88 */       if (str.equals(localVirtualFilePointer.getUrl()))
/*  84:    */       {
/*  85: 89 */         if (paramString == null)
/*  86:    */         {
/*  87: 90 */           this.a.remove(localVirtualFilePointer);
/*  88: 91 */           return;
/*  89:    */         }
/*  90: 92 */         if (!paramString.equals(((VirtualFilePointer)this.a.get(localVirtualFilePointer)).getUrl()))
/*  91:    */         {
/*  92: 93 */           this.a.remove(localVirtualFilePointer);
/*  93: 94 */           this.a.put(localVirtualFilePointer, localVirtualFilePointerManager.create(paramString, this.b, null));
/*  94: 95 */           return;
/*  95:    */         }
/*  96:    */       }
/*  97:    */     }
/*  98:100 */     if (paramString != null) {
/*  99:101 */       this.a.put(localVirtualFilePointerManager.create(str, this.b, null), localVirtualFilePointerManager.create(paramString, this.b, null));
/* 100:    */     }
/* 101:    */   }
/* 102:    */   
/* 103:    */   public void initComponent() {}
/* 104:    */   
/* 105:    */   public void disposeComponent() {}
/* 106:    */   
/* 107:    */   @NotNull
/* 108:    */   public String getComponentName()
/* 109:    */   {
/* 110:113 */     String tmp2_0 = "RELAX-NG.NoNamespaceConfig";
/* 111:113 */     if (tmp2_0 == null) {
/* 112:113 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/plugins/relaxNG/config/NoNamespaceConfigImpl", "getComponentName" }));
/* 113:    */     }
/* 114:113 */     return tmp2_0;
/* 115:    */   }
/* 116:    */   
/* 117:    */   public void projectOpened() {}
/* 118:    */   
/* 119:    */   public void projectClosed()
/* 120:    */   {
/* 121:120 */     a();
/* 122:    */   }
/* 123:    */   
/* 124:    */   public Mappings getState()
/* 125:    */   {
/* 126:124 */     HashMap localHashMap = new HashMap();
/* 127:125 */     for (Map.Entry localEntry : this.a.entrySet()) {
/* 128:126 */       localHashMap.put(((VirtualFilePointer)localEntry.getKey()).getUrl(), ((VirtualFilePointer)localEntry.getValue()).getUrl());
/* 129:    */     }
/* 130:128 */     return new Mappings(localHashMap);
/* 131:    */   }
/* 132:    */   
/* 133:    */   public void loadState(Mappings paramMappings)
/* 134:    */   {
/* 135:132 */     a();
/* 136:    */     
/* 137:134 */     VirtualFilePointerManager localVirtualFilePointerManager = VirtualFilePointerManager.getInstance();
/* 138:135 */     Map localMap = paramMappings.myMappings;
/* 139:136 */     for (String str : localMap.keySet()) {
/* 140:137 */       this.a.put(localVirtualFilePointerManager.create(str, this.b, null), localVirtualFilePointerManager.create((String)localMap.get(str), this.b, null));
/* 141:    */     }
/* 142:    */   }
/* 143:    */   
/* 144:    */   private void a()
/* 145:    */   {
/* 146:142 */     this.a.clear();
/* 147:    */   }
/* 148:    */   
/* 149:    */   public static class Mappings
/* 150:    */   {
/* 151:    */     @MapAnnotation(surroundWithTag=false, entryTagName="mapping", keyAttributeName="file", valueAttributeName="schema")
/* 152:    */     public Map<String, String> myMappings;
/* 153:    */     
/* 154:    */     public Mappings()
/* 155:    */     {
/* 156:151 */       this.myMappings = new HashMap();
/* 157:    */     }
/* 158:    */     
/* 159:    */     Mappings(Map<String, String> paramMap)
/* 160:    */     {
/* 161:155 */       this.myMappings = paramMap;
/* 162:    */     }
/* 163:    */   }
/* 164:    */   
/* 165:    */   public static class HectorProvider
/* 166:    */     implements HectorComponentPanelsProvider
/* 167:    */   {
/* 168:    */     @Nullable
/* 169:    */     public HectorComponentPanel createConfigurable(@NotNull PsiFile paramPsiFile)
/* 170:    */     {
/* 171:162 */       if (paramPsiFile == null) {
/* 172:162 */         throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/intellij/plugins/relaxNG/config/NoNamespaceConfigImpl$HectorProvider", "createConfigurable" }));
/* 173:    */       }
/* 174:162 */       if ((paramPsiFile instanceof XmlFile)) {
/* 175:    */         try
/* 176:    */         {
/* 177:164 */           XmlTag localXmlTag = ((XmlFile)paramPsiFile).getDocument().getRootTag();
/* 178:165 */           if (localXmlTag.getNamespace().length() == 0) {
/* 179:166 */             return new NoNamespaceConfigPanel(NoNamespaceConfig.getInstance(paramPsiFile.getProject()), paramPsiFile);
/* 180:    */           }
/* 181:    */         }
/* 182:    */         catch (NullPointerException localNullPointerException)
/* 183:    */         {
/* 184:169 */           return null;
/* 185:    */         }
/* 186:    */       }
/* 187:172 */       return null;
/* 188:    */     }
/* 189:    */   }
/* 190:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.plugins.relaxNG.config.NoNamespaceConfigImpl

 * JD-Core Version:    0.7.0.1

 */